package com.jianjian.service.Impl;

import com.jianjian.dao.UserDao;
import com.jianjian.service.UserService;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author Zsir
 * @create 2021-12-11 18:06
 */
public class UserServiceImpl implements UserService {
 private UserDao userDao;

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public void save() {
        System.out.println("我是谁啊");
    }
    @Test
    public void  test1(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserDao userDao = (UserDao) applicationContext.getBean("userDao");

        userDao.save();
    }

    @Test
    public void test2() throws SQLException {
      ApplicationContext applicationContext=    new ClassPathXmlApplicationContext("applicationContext.xml");
        DataSource datasource = (DataSource) applicationContext.getBean("datasource");
        Connection connection = datasource.getConnection();
        System.out.println(connection);

    }
}
